﻿<!DOCTYPE html>
<html>

<head>
	<meta charset=utf-8>
	<title>Effekseer For Cocos2d-x</title>
	<link href="base.css" rel="stylesheet" type="text/css" />
</head>

<body>
	<div class="main">
		<h1>Effekseer For Cocos2d-x</h1>
		
		<h2>摘要</h2>

		<p>
		Effekseer是一個可以輕鬆地創建美麗的粒子效果的工具。本程式庫將能夠在Cocos2d-X內播放由Effekseer創建而成的粒子效果。
        本文檔會介紹如何在Cocos2d-x內使用本程式庫。
        程式庫是由複數源代碼組成，通過新增本源代碼便可為Cocos2d-x進行安裝。
		</p>

		<p>
        對應環境如下
		</p>

		<table>
			<tr>
				<td>Windows</td>
				<td>OK</td>
			</tr>

			<tr>
				<td>Mac OS X</td>
				<td>OK</td>
			</tr>

			<tr>
				<td>Linux</td>
				<td>Unknown</td>
			</tr>

			<tr>
				<td>iOS</td>
				<td>OK</td>
			</tr>

			<tr>
				<td>Android</td>
				<td>OK</td>
			</tr>

			<tr>
				<td>WindowsPhone</td>
				<td>Unknown</td>
			</tr>

		</table>

		<div align="Center">
			<img src="Top.png">
		</div>

		<h2>如何安裝</h2>
		<p>
		<b>Players/Cocos2d-x_v3</b>的文件夾內會包含以下文件。
		</p>

<ul>
<li>Effekseer.cpp</li>
<li>Effekseer.h</li>
<li>EffekseerNative.cpp</li>
<li>EffekseerNative.h</li>
<li>EffekseerRendererNative.cpp</li>
<li>EffekseerRendererNative.h</li>
</ul>

		<p>
		將這些文件複製到的Cocos2d-x的文件夾內，再設定成編譯對象。
		</p>


		<h2>如何使用</h2>

<p>
在<b>Samples/</b>文件夾內會有在Cocos2d-x內播放Effekseer粒子效果的樣本。本文件只會作出簡單的使用方法。詳細請參閱樣本。
</p>

<p>
樣本是不包含在此程式庫內，請將各樣本複製到<b>Classes/Effekseer</b>文件夾內使用。
為方便得知文件存放的位置、會有一個名為<b>copyEffekseerFiles.txt</b>的文件作為標籤而作識別。
</p>

<h3>有關可播放的文件</h3>

<p>
您只可以播放由Effekseer保存而成的文件。由Effekseer保存的文件中包含圖像的相對路徑。因此，請留意各檔案的存放位置。
</p>

<h3>基本播放</h3>

<p>
由Effekseer保存而成的文件可在cocos2d-x內播放。 欲了解更多資訊，請查看存儲在<b>Samples/Simple/</b>內的源代碼。
</p>

<br>

<p>
包括Effekseer.h。
</p>

<pre>
#include "Effekseer/Effekseer.h"
</pre>
<br>

<p>
在cocos2d::Scene或Layer的衍生類別內加入成員變量efk::EffectManager*。
</p>

<pre>
class HelloWorld : public cocos2d::Scene /* Layer */ {
efk::EffectManager* manager = nullptr;
...
</pre>
<br>

<p>
建立執行個體efk::EffectManager*。
</p>

<pre>
manager = efk::EffectManager::create(Director::getInstance()->getVisibleSize());
</pre>
<br>

<p>
讀取粒子效果文件。
</p>

<pre>
auto effect = efk::Effect::create("Laser01.efk");
</pre>
<br>

<p>
建立發射極，並通過將參數添加到階層。
</p>

<pre>
auto emitter = efk::EffectEmitter::create(manager);
emitter->setEffect(effect);
emitter->setPlayOnEnter(true);

emitter->setPosition(Vec2(300, 300));
emitter->setScale(20);
this->addChild(emitter, 0);

// No need (because it uses autorelease after 1.41)
//effect->release();
</pre>

<p>
更新畫面。
</p>

<pre>
manager->update();
</pre>
<br>

<p>
衍生visit，使可添加的繪製效果的處理。
</p>

<pre>
void HelloWorld::visit(
	cocos2d::Renderer *renderer, 
	const cocos2d::Mat4& parentTransform, 
	uint32_t parentFlags)
{
	manager->begin(renderer, _globalZOrder);
	cocos2d::Scene::visit(renderer, parentTransform, parentFlags);
	manager->end(renderer, _globalZOrder);
}
</pre>
<br>

<p>
刪除執行個體。
</p>

<pre>
HelloWorld::~HelloWorld()
{
	manager->release();
}
</pre>

<h3>3D</h3>

<p>請閱讀 <b>Samples/3D/</b> 中的示例. </p>

<p>你需要在cocos2d-x的Scene中添加一個攝像頭</p>

<pre>
auto s = Director::getInstance()->getWinSize();
camera = Camera::createPerspective(60, (GLfloat)s.width / s.height, 1, 1000);
camera->setPosition3D(Vec3(100, 100, 100));
camera->lookAt(Vec3(0, 0, 0), Vec3(0, 1, 0));
camera->setCameraFlag(cocos2d::CameraFlag::USER1);
</pre>


<p>
除了更新manager之外，還需要將攝像機參數設置到manager中。
</p>
		
<pre>
manager->update();
manager->setCameraMatrix(camera->getViewMatrix());
manager->setProjectionMatrix(camera->getProjectionMatrix());
</pre>

<h3>網絡</h3>

<p>當應用程序運行時，您可以從外部通過網絡編輯應用程序（遊戲等）中的播放效果。</p>

<img src="img/network.png" width="800">

<p>創建服務器實例並使用要從Effekseer連接的端口執行makeNetworkServerEnabled作為此函數的參數。 </p>

<pre>
networkSever = efk::NetworkServer::create();
networkSever->makeNetworkServerEnabled(60000);
</pre>

<p>
除了更新manager之外，還需要更新服務器。然後你可以編輯Effekseer的效果。要從另一台計算機編輯效果，必須使用防火牆的設置打開端口。
</p>

<pre>
manager->update();
networkSever->update();
</pre>

		<h2>授權</h2>

<p>
如使用Effekseer，你需要添加下面的措辭。（例如在幫助內）
</p>

<pre>
The MIT License (MIT)

Copyright (c) 2011 Effekseer Project

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
</pre>

<h2>更新</h2>

<h3>1.43c (19/09/16)</h3>
<p>fixed a bug which causes crash if PlayOnEnter is false, and call play after next frame</p>
<p>fixed a bug that parameters are not applied which are assigned before playing</p>

<h3>1.43b (19/08/03)</h3>
<p>Fixed OpenGL blend bug</p>
<p>Fixed Samples</p>

<h3>1.43 (19/03/02)</h3>
<p>Added network functions</p>

<h3>1.42 (19/02/08)</h3>
<p>Added image caching function</p>
<p>Added documentation</p>
<p>Fixed bug that the behavior of the ribbon and track generated with the 0th frame is wrong</p>
<p>Fixed bug that SSE buffer overrun crashes</p>
<p>Fixed bug that crashes on Android when specifying easing of color</p>

<h3>1.41 (18/11/10) </h3>
<p>Fixed a bug causes crach when setRemoveOnStop is used. Fixed memory leak in samples.</p>
<p>This release makes Effect and EffectEmitter released automatically. So you need to edit codes about release</p>

<p>1.40 (18/09/12) More functions added. Speed up with Android and iOS. Supported 3D.</p>

<p>1.30 (17/11/03) 發布。</p>

	</div>
</body>

</html>
